package initialize

import (
	"context"
	"github.com/cy77cc/hioshop/config"
	"github.com/redis/go-redis/v9"
)

func InitRedisDB(cfg config.Redis) (*redis.Client, error) {
	client := redis.NewClient(&redis.Options{
		Addr: cfg.Addr,
	})

	ctx := context.Background()

	ping := client.Ping(ctx)
	if err := ping.Err(); err != nil {
		//global.LOG.Error("redis connect ping failed, err:", zap.String("name", cfg.Username), zap.Error(err))
		return nil, ping.Err()
	}

	return client, nil
}
